import React from "react"
import Appcss from "./css/Login.module.css"
import Register from "../Register"
import fanh from '../../assets/icons/返回箭头.png'
import { List,InputItem} from 'antd-mobile';
import {BrowserRouter as Router,Route,Link} from "react-router-dom"
import { Toast, WhiteSpace, WingBlank, Button } from 'antd-mobile';
// import { createForm } from 'rc-form';
// import Logo from '../assets/icons/logo.png'
class Cell_login extends React.Component {
    constructor(){
        super()
        this.state={
            phone:"",
            mima:"",
            check:""
        }
    }
    login(){
        fetch(`http://106.12.79.128:666/login/cellphone?phone=${this.state.phone}&password=${this.state.mima}`,{  credentials:'include'})
        .then(body=>body.json())
        .then(res=>{
            if(res.code==200){
                console.log(res)
                localStorage.setItem("tokenJson", res.bindings[0].tokenJsonStr)
               localStorage.setItem("nickname", res.profile.nickname)
               localStorage.setItem("userid",res.account.id)
            Toast.loading('Loading...', 1, () => {
                console.log('Load complete !!!');
                this.props.history.push({pathname:"/gen/My",id:res.account.id})
              });
            console.log(res)}
            else{
                Toast.fail('账号或密码错误', 1); 
            }
        })
        // .catch(
        //     Toast.fail('账号或密码错误', 1);
        // )
    }
    // ipt1(e){
    //     var uPattern = /^1\d{11}$/;
    //     if(!uPattern.test(e.target.value)){
    //     this.setState({
    //         phone:e.target.value,
    //     })}else{
    //         alert(1111)
    //     }

    // }


    zz(e){
        var uPattern = /^1\d{10}$/;
        if(!uPattern.test(e.target.value)){
            Toast.offline('手机号必须是11位!', 1);
        }
        // if(!uPattern.test(e.target.value)){
        // this.setState({
        //     phone:e.target.value,
        // })}else{
        //     alert(1111)
        // }
        else{
            this.setState({
                    phone:e.target.value,
                })
        }
    }
    zz2(e){
        var uPattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$/;
        if(!uPattern.test(e.target.value)){
            // alert('密码必须是6位')
            Toast.offline('密码必须由6位以上数字和字母组成!', 1);
        }
        else{
            this.setState({
                    mima:e.target.value,
                })
        }
    }

    jump(){
        this.props.history.push({pathname:"/register"})
        // console.log(this.props)
    }
    fanhu(){
        this.props.history.push({pathname:"/BasicInputExample"})
    }
    update(){
        this.props.history.push({pathname:"/update"})
    }
    render(){
        return(
   
       
        <div className={Appcss.cel_log}>
          
             <div className={Appcss.cel_zc}>
                <span id={Appcss.cel_fh} onClick={this.fanhu.bind(this)}><img src={fanh} width='100%' height='100%' alt=''/></span>
                <span id={Appcss.cel_reg}>手机号登录</span>
                </div>
            
            <div >
                <input type="text" className={Appcss.cel_ce} placeholder="请输入手机号" onBlur={this.zz.bind(this)} ></input>
                {/* onChange={this.ipt1.bind(this)} value={this.state.phone}  */}
             </div>
             {/* <div className={Appcss.cel_check}>{this.state.check}</div> */}
             <div >
               <input type="password" className={Appcss.cel_pa} placeholder="请输入密码" onBlur={this.zz2.bind(this)}></input>
             </div>
             <div className={Appcss.cel_span}>
                 {/* <input type="checkbox"/> */}
                 <span onClick={this.update.bind(this)}>忘记密码</span>
                 <span onClick={this.jump.bind(this)}>注册账号</span>
               
             </div>
			<button className={Appcss.cel_lo} onClick={this.login.bind(this)}>登录</button><br/>
            <span className={Appcss.cel_qtdl} onClick={this.fanhu.bind(this)}>&lt;其他登录方式</span>
            
           
		</div>
    
        )
    }



}
// const Cell_login1 = createForm()(Cell_login);
export default Cell_login